//
//	 ______    ______    ______    
//	/\  __ \  /\  ___\  /\  ___\   
//	\ \  __<  \ \  __\_ \ \  __\_ 
//	 \ \_____\ \ \_____\ \ \_____\ 
//	  \/_____/  \/_____/  \/_____/ 
//
//	Powered by BeeFramework
//
//
//  AddActivityBoard.m
//  iHeima
//
//  Created by he chao on 6/4/14.
//  Copyright (c) 2014 leon. All rights reserved.
//

#import "AddActivityBoard.h"

#pragma mark -

@interface AddActivityBoard()<UITextViewDelegate>
{
	//<#@private var#>

    UITextView* myTextView;
    
    UILabel*  _placeLabel;
    
}




@end

@implementation AddActivityBoard
DEF_SIGNAL(ADD)

- (void)load
{
}

- (void)unload
{
}


#pragma mark - Signal

ON_CREATE_VIEWS( signal )
{
    self.title = @"我要报名";
    [self showBarButton:BeeUINavigationBar.LEFT title:@"取消"];
    [self showNaviBar];
    [self loadContent];
}

ON_DELETE_VIEWS( signal )
{
}

ON_LAYOUT_VIEWS( signal )
{
}

ON_WILL_APPEAR( signal )
{
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

ON_DID_APPEAR( signal )
{
}

ON_WILL_DISAPPEAR( signal )
{
}

ON_DID_DISAPPEAR( signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, LEFT_TOUCHED, signal )
{
    [self.navigationController dismissViewControllerAnimated:YES completion:^{
        
    }];
}

ON_SIGNAL3( BeeUINavigationBar, RIGHT_TOUCHED, signal )
{
}

ON_SIGNAL2(AddActivityBoard, signal){
    if ([signal is:AddActivityBoard.ADD]) {
        if (myTextView.text.length==0) {
            [[BeeUITipsCenter sharedInstance] presentMessageTips:@"请输入内容"];
            return;
        }
        BeeHTTPRequest *request = [self POST:[NSString stringWithFormat:@"%@/apiactivity/apply/",kBaseUrl]].PARAM(@"uid",kUserInfo[@"uid"]).PARAM(@"activityid",self.dictActivity[@"id"]).PARAM(@"intro",myTextView.text);
        request.tag = 9527;
    }
}




- (void)handleRequest:(BeeRequest *)request
{
    if(request.failed)
    {
        [[BeeUITipsCenter sharedInstance] dismissTips];
        NETWORK_ERROR
    }
    else if (request.succeed)
    {
        id json = [request.responseString mutableObjectFromJSONString];
       // NSLog(@"%@",json);
        switch ([json[@"status"] intValue]) {
            case 1:
            {
                [[BeeUITipsCenter sharedInstance] presentMessageTips:@"报名成功"];
                [self.navigationController dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }
                break;
            default:
            {
                [[BeeUITipsCenter sharedInstance] presentMessageTips:json[@"info"]];
            }
                break;
        }
    }
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
 replacementText:(NSString *)text {
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}


-(void)textViewDidChange:(UITextView *)textView
{
    //self.examineText =  textView.text;
    if (textView.text.length == 0) {
        _placeLabel.text = @"一句话介绍自己的情况";
    }else{
        _placeLabel.text = @"";
    }
}

- (void)loadContent{
//    _textView = [BeeUITextView spawn];
//    _textView.frame = CGRectMake(0, 0, self.viewWidth, 155);
//    _textView.backgroundColor = RGB(244, 244, 244);
//    
//    _textView.returnKeyType = UIReturnKeyDone;
//    [self.view addSubview:_textView];
//    
//    _textView.placeholder = @"请输入报名信息";
//    
//    
//    _textView.delegate = self;
    
    
    myTextView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, self.viewWidth, 155)];
    myTextView.backgroundColor =  RGB(244, 244, 244);
    myTextView.returnKeyType = UIReturnKeyDone;
    [self.view addSubview:myTextView];
    
    myTextView.delegate  = self;
    
    _placeLabel = [[UILabel alloc]initWithFrame:CGRectMake(2, 3, 320, 30)];
    _placeLabel.text = @"一句话介绍自己的情况";
    _placeLabel.textColor = [UIColor grayColor];
    _placeLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:_placeLabel];

    
    BaseButton *btn = [BaseButton initBaseBtn:IMAGESTRING(@"btn1") highlight:IMAGESTRING(@"btn1_pre") text:@"我要报名" textColor:[UIColor whiteColor] font:FONT(14)];
    btn.frame = CGRectMake(65, myTextView.bottom+20, 190, 44);
    [btn addSignal:AddActivityBoard.ADD forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}




@end
